package com.hyj.ecp.backstage.statistics.bean;

import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.Map.Entry;

public class MsColumnXML {
  
	public static String getMsColumnXml(String caption,String xAxisName,String yAxisName,String numberPrefix){
		return msColumn.replace("{caption}",caption).replace("{xAxisName}", xAxisName)
		.replace("{yAxisName}", yAxisName).replace("{numberPrefix}", numberPrefix);
	}
	
	public static  String  getMsColumnXml(String caption, String xAxisName,
			String yAxisName, String numberPrefix, List<Map<String,Object>> data,List<String> series) {
		StringBuffer sb1 = new StringBuffer();
		StringBuffer sb2 = new StringBuffer();
        for(int i = 0;i<data.size();i++){
        	Map<String,Object> map = data.get(i);
        	Set<Entry<String,Object>> sets = map.entrySet();
        	sb2.append("<dataset seriesName='"+series.get(i)+"'>");
        	Iterator<Entry<String,Object>> it = sets.iterator();
        	while(it.hasNext()){
        		Entry<String,Object> ent = it.next();
        		String key = ent.getKey();
        		Object value = ent.getValue();
        		if(i<=0){
        		 sb1.append("<category label='"+key+"'/>");
        		}
        		sb2.append("<set value='"+value+"' />");
        	}
        	sb2.append("</dataset>");
        	
        }
		return msXmlBase.replace("{caption}",caption).replace("{xAxisName}", xAxisName)
		.replace("{yAxisName}", yAxisName).replace("{numberPrefix}", numberPrefix)
		.replace("{categories}", sb1.toString()).replace("{dataset}", sb2.toString());
	}
	
	private static String msXmlBase =
	"<chart caption='{caption}' xAxisName='{xAxisName}' yAxisName='{yAxisName}' showValues='1' yAxisNameWidth='20' rotateYAxisName='0' " +
	"   formatNumberScale='0'   numberPrefix='{numberPrefix}'>"+
	"<categories>"+
	" {categories} "+
	"</categories>"+
	"{dataset}"+
    "<styles>"+
	    "<definition>"+
	          "<style name='CanvasAnim' type='animation' param='_xScale' start='0' duration='1' />"+
	    "</definition>"+
	
	    "<application>"+
	          "<apply toObject='Canvas' styles='CanvasAnim' />"+
	    "</application>"+   
    "</styles>"+
   "</chart> ";
	
	private static String msColumn  =
"<chart caption='{caption}' xAxisName='{xAxisName}' yAxisName='{yAxisName}' showValues='1' yAxisNameWidth='20'  rotateYAxisName='0' " +
"   formatNumberScale='0'   numberPrefix='{numberPrefix}'>"+
    "<categories>"+
       "<category label='Jan'/>"+
       "<category label='Feb' />"+
       "<category label='Mar' />"+
       "<category label='Apr' />"+
       "<category label='May' />"+
       "<category label='Jun' />"+
       "<vLine color='FF5904' thickness='2'/> "+
       "<category label='Jul' />"+
       "<category label='Aug' />"+
       "<category label='Sep' />"+
       "<category label='Oct' />"+
       "<category label='Nov' />"+
       "<category label='Dec' />"+
    "</categories>"+
    "<dataset seriesName='2012'>"+
       "<set value='27401' />"+
       "<set value='29800' />"+
       "<set value='25800' />"+
       "<set value='26800' />"+
       "<set value='29600' />"+
       "<set value='32600' />"+
       "<set value='31800' />"+
       "<set value='36700' />"+
       "<set value='29700' />"+
       "<set value='31900' />"+
       "<set value='34800' />"+
       "<set value='24800' />"+
    "</dataset>"+
    "<dataset seriesName='2013'>"+
       "<set value='10000' />"+
       "<set value='11500' />"+
       "<set value='12500' />"+
       "<set value='170970' />"+
       "<set value='11000' />"+
       "<set value='9800' />"+
       "<set value='11800' />"+
       "<set value='19700' />"+
       "<set value='21700' />"+
       "<set value='21900' />"+
       "<set value='22900' />"+
       "<set value='20800' />"+
    "</dataset>"+
 
    "<trendlines>"+
       "<line startValue='26000' color='91C728' displayValue='Target' showOnTop='1'/>"+
    "</trendlines>"+
 
    "<styles>"+
       "<definition>"+
             "<style name='CanvasAnim' type='animation' param='_xScale' start='0' duration='1' />"+
       "</definition>"+
 
       "<application>"+
             "<apply toObject='Canvas' styles='CanvasAnim' />"+
       "</application>"+   
    "</styles>"+
 
 "</chart> ";
	
}
